package test.tool;



import java.util.Iterator;
import java.util.concurrent.ConcurrentLinkedQueue;

/**
 * 循环链表
 * @author 程序园中猿
 */
public class CircularLinkedList<T> {
    private ConcurrentLinkedQueue<T> list;
    private Iterator<T> iterator;

    public CircularLinkedList() {
        list = new ConcurrentLinkedQueue<>();
        iterator = list.iterator();
    }

    public void add(T t) {
        list.add(t);
    }

    public T next() {
        if (!iterator.hasNext()) {
            iterator = list.iterator();
        }
        return iterator.next();
    }

}
